home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / earcd / biz / dbase / msql_2_b.lha / Hughes / include / lite.h next >
C/C++ Source or Header  |  1997-04-08  |  9KB  |  380 lines

  1.  
  2.  
  3. #include <sys/types.h>
  4. #include <common/portability.h>
  5.  
  6.  
  7.  
  8. typedef    u_char    *U_C_PTR;
  9.  
  10. #undef  YYSTYPE
  11. #define    YYSTYPE    U_C_PTR
  12.  
  13.  
  14. typedef struct code_s {
  15.     char    op;
  16.     char    *arg;
  17.     u_short    label;
  18.     short    type;
  19.     u_short    line;
  20.     char    file;
  21.     struct code_s *next,
  22.         *prev;
  23. } code_t;
  24.  
  25.  
  26.  
  27. typedef struct _sym {
  28.         char    *name,
  29.                 *val;
  30.         short    type;
  31.     char    array,
  32.         usign;
  33.         int     length,
  34.         source;
  35.         struct _sym *next;
  36. } sym_t;
  37.  
  38.  
  39. typedef struct _funct {
  40.     char    *name;
  41.     code_t    *code;
  42.     sym_t    *params;
  43.     struct     _funct *next;
  44. } funct_t;
  45.  
  46.  
  47. typedef    struct array_s {
  48.     sym_t    *sym;
  49.     struct    array_s *next;
  50. } array_t;
  51.  
  52.  
  53.  
  54. typedef struct stack_s {
  55.     u_short    block;
  56.     short    type;
  57.     sym_t    *sym;
  58.     struct    stack_s *next;
  59. } sstack_t;
  60.  
  61.  
  62. typedef struct plist_s {
  63.         sym_t    *sym;
  64.         struct  plist_s *next;
  65. } plist_t;
  66.  
  67.  
  68. typedef struct efunct_s {
  69.         char    *name;
  70.         void    (*funct) ();
  71.     char    *functName;
  72.         int        numParams;
  73.         int     paramTypes[20];
  74. } efunct_t;
  75.  
  76.  
  77.  
  78. typedef struct fbucket_s {
  79.         efunct_t                *funct;
  80.         struct fbucket_s        *next;
  81. } fbucket_t;
  82.  
  83.  
  84. typedef struct lstack_s {
  85.     int    label;
  86.     struct    lstack_s    *next;
  87. } lstack_t;
  88.  
  89.  
  90. typedef struct type_s {
  91.     char    *name;
  92.     int    length;
  93.     int    (*pack)();
  94.     int    (*unpack)();
  95.     int    (*read)();
  96.     int    (*write)();
  97.     int    (*compare)();
  98.     int    (*math)();
  99.     int    (*check)();
  100. } type_t;
  101.  
  102.  
  103.  
  104. #define    OP_CALL        1
  105. #define OP_PUSH        2
  106. #define OP_CMP        3
  107. #define OP_JMP        4
  108. #define OP_JMP_FALSE    5
  109. #define OP_JMP_BACK    6
  110. #define OP_LABEL    7
  111. #define OP_STORE    8
  112. #define OP_A_STORE    9
  113. #define OP_DEREF    10
  114. #define OP_ALU        11
  115. #define OP_BLOCK_IN    12
  116. #define OP_BLOCK_OUT    13
  117. #define OP_EXIT        14
  118. #define OP_ECHO        15
  119. #define OP_CAST        16
  120. #define OP_COUNT    17
  121. #define OP_PUSHRET    18
  122. #define OP_RETURN    19
  123.  
  124. #define    OP_ADD        100
  125. #define OP_SUB        101
  126. #define OP_MUL        102
  127. #define OP_DIV        103
  128. #define OP_AND        105
  129. #define OP_OR        106
  130. #define OP_MOD        107
  131.  
  132. #define SCALAR        1
  133. #define ARRAY        2
  134. #define    VARIABLE    3
  135.  
  136. #define    TYPE_REAL    0
  137. #define    TYPE_INT    1
  138. #define    TYPE_CHAR    2
  139. #define    TYPE_UINT    3
  140.  
  141.  
  142. #define    P_TEXT        1
  143. #define    P_INT        2
  144. #define P_ARRAY        3
  145.  
  146.  
  147. #define    SRC_POST    1
  148. #define SRC_IMPORT    2
  149. #define SRC_GET        3
  150. #define SRC_SECURE    SRC_IMPORT
  151.  
  152. #define SYM_HASH_SIZE   64
  153.  
  154.  
  155. /*
  156. ** Pre declarations
  157. */
  158.  
  159. #if defined(__STDC__) || defined(__cplusplus)
  160. #  define __ANSI_PROTO(x)       x
  161. #else
  162. #  define __ANSI_PROTO(x)       ()
  163. #endif
  164.  
  165.  
  166.  
  167. /* Lexer / Parser */
  168.  
  169. int    yylex();
  170. int    yyparse();
  171. void    yyerror __ANSI_PROTO((char *));
  172. void    parseError __ANSI_PROTO((char *));
  173. void    runError __ANSI_PROTO((char *));
  174. void     lexInitScanner __ANSI_PROTO((u_char *));
  175. void     sendFooter ();
  176.  
  177.  
  178. /* Symbol table routines */
  179.  
  180. int symCheckSymbol __ANSI_PROTO((char *));
  181. int symGetNumArrayElements __ANSI_PROTO((sym_t *));
  182. int symSetArray __ANSI_PROTO((char *, sym_t *));
  183.  
  184. char *expandText __ANSI_PROTO((char *));
  185. char *symUnpackSymbol __ANSI_PROTO((sym_t *));
  186.  
  187. sym_t *createArray();
  188. sym_t *createArrayLiteral();
  189. sym_t *createCharSymbol __ANSI_PROTO((char *));
  190. sym_t *createIntSymbol __ANSI_PROTO((int));
  191. sym_t *createRealSymbol __ANSI_PROTO((double));
  192. sym_t *createUintSymbol __ANSI_PROTO((int));
  193. sym_t *symCreateLiteral __ANSI_PROTO((char *, int));
  194. sym_t *symCreateMacroLiteral __ANSI_PROTO((char *));
  195. sym_t *symCreateSymbol __ANSI_PROTO((char *, int, int));
  196. sym_t *symGetArrayElement __ANSI_PROTO((sym_t *, int));
  197. sym_t *symGetEnvironVariable __ANSI_PROTO((char *));
  198. sym_t *symGetMacro __ANSI_PROTO((char *));
  199. sym_t *symGetSymbol __ANSI_PROTO((char *));
  200. sym_t *symdup __ANSI_PROTO((sym_t *));
  201.  
  202. void initSymbolTables();
  203. void symAddArrayElement __ANSI_PROTO((char *));
  204. void symClearArray __ANSI_PROTO((sym_t *));
  205. void symCreateArrayGlobal __ANSI_PROTO((char *,char **,int));
  206. void symCreateCharGlobal __ANSI_PROTO((char *,char *));
  207. void symCreateCharMacro __ANSI_PROTO((char *,char *));
  208. void symCreateIntGlobal __ANSI_PROTO((char *,int));
  209. void symCreateIntMacro __ANSI_PROTO((char *,int));
  210. void symCreateRealGlobal __ANSI_PROTO((char *,double));
  211. void symCreateRealMacro __ANSI_PROTO((char *,double));
  212. void symFreeSymbol __ANSI_PROTO((sym_t *));
  213. void symFreeSymbolData __ANSI_PROTO((sym_t *));
  214. void symSetArrayElement __ANSI_PROTO((sym_t *, int, sym_t *));
  215. void symSetValue __ANSI_PROTO((sym_t *, sym_t *));
  216. void symStackIn();
  217. void symStackOut();
  218. void symStoreSymbol __ANSI_PROTO((sym_t **, sym_t *));
  219. void symTypeCast __ANSI_PROTO((sym_t *,int));
  220.  
  221. array_t *symArrayDup __ANSI_PROTO((sym_t *));
  222.  
  223.  
  224. /* Code generation routines */
  225.  
  226. int     addFunction __ANSI_PROTO((char *));
  227. int     addParam __ANSI_PROTO((char *, char *));
  228. int     codePopBreak();
  229. int     codePopContinue();
  230. int     codePopLabel();
  231. int     popBreak ();
  232. int     popContinue ();
  233. int     popLabel ();
  234.  
  235. void     codeALU __ANSI_PROTO((int));
  236. void     codeArrayStore __ANSI_PROTO((char *));
  237. void     codeBlockIn();
  238. void     codeBlockOut();
  239. void     codeCall __ANSI_PROTO((char *));
  240. void     codeCast __ANSI_PROTO((char *));
  241. void     codeCmp __ANSI_PROTO((int));
  242. void     codeCount();
  243. void     codeDeref __ANSI_PROTO((char *));
  244. void     codeEcho __ANSI_PROTO((char *));
  245. void     codeExit ();
  246. void     codeHtml __ANSI_PROTO((int, int));
  247. void     codeJmp __ANSI_PROTO((int));
  248. void     codeJmpBack __ANSI_PROTO((int));
  249. void     codeJmpFalse __ANSI_PROTO((int));
  250. void     codeLabel __ANSI_PROTO((int));
  251. void     codePush __ANSI_PROTO((char *));
  252. void     codePushBreak __ANSI_PROTO((int));
  253. void     codePushContinue __ANSI_PROTO((int));
  254. void     codePushLabel __ANSI_PROTO((int));
  255. void     codePushRet();
  256. void     codeReturn();
  257. void     codeStore __ANSI_PROTO((char *));
  258. void     dumpCode ();
  259. void     endOfFunction();
  260. void     pushBreak __ANSI_PROTO((int));
  261. void     pushContinue __ANSI_PROTO((int));
  262. void     pushLabel __ANSI_PROTO((int));
  263.  
  264.  
  265. /* Code simulation routines */
  266.  
  267. int    checkNumeric __ANSI_PROTO((char *));
  268. int    getLine();
  269. int    runCode __ANSI_PROTO((char *));
  270. int     simGetLineNum();
  271.  
  272. char *simGetFileName();
  273.  
  274. void    doExit();
  275. void    doBlockIn();
  276. void    doBlockOut();
  277. void    doCall __ANSI_PROTO((code_t *));
  278. void    doEcho __ANSI_PROTO((plist_t *));
  279. void    doPushVar __ANSI_PROTO((code_t *));
  280. void    doPushVal __ANSI_PROTO((code_t *));
  281. void    doPushLiteral __ANSI_PROTO((code_t *));
  282. void    doStore __ANSI_PROTO((code_t *));
  283. void    doArrayStore __ANSI_PROTO((code_t *));
  284. void    doDeref __ANSI_PROTO((code_t *));
  285. void    doALU __ANSI_PROTO((code_t *));
  286. void    doCmp __ANSI_PROTO((code_t *));
  287.  
  288.  
  289.  
  290. /* External interface routines */
  291.  
  292. int    calcHash __ANSI_PROTO((char *));
  293. int    getNumArrayElements __ANSI_PROTO((array_t *));
  294. int     hex2dec __ANSI_PROTO((char *));
  295. int     modLoadModule __ANSI_PROTO((char *));
  296. int     modLoadModuleFunctions __ANSI_PROTO((void *, efunct_t *));
  297. int     oct2dec __ANSI_PROTO((char *));
  298. int    str2int __ANSI_PROTO((char *));
  299.  
  300. char    *deleteObject __ANSI_PROTO((u_int));
  301. char    *fetchObject __ANSI_PROTO((u_int));
  302. char    *getArrayElement __ANSI_PROTO((array_t *, int));
  303. char    *int2str __ANSI_PROTO((int));
  304.  
  305. void    addExterns __ANSI_PROTO((efunct_t *));
  306. void    setReturnValue __ANSI_PROTO((char *, int));
  307. void    setupModules ();
  308.  
  309. sym_t     *createArray();
  310.  
  311. u_int    storeObject __ANSI_PROTO((char *));
  312.  
  313. efunct_t *findExtern __ANSI_PROTO((char *));
  314.  
  315.  
  316. /* Type handling routines */
  317.  
  318. type_t     *typeGetType __ANSI_PROTO((int));
  319. int     typeGetTypeIndex __ANSI_PROTO((char *));
  320.  
  321. sym_t    *createIntSymbol __ANSI_PROTO((int));
  322. sym_t    *createRealSymbol __ANSI_PROTO((double));
  323. sym_t    *createCharSymbol __ANSI_PROTO((char *));
  324.  
  325.  
  326.  
  327. /* lib.c prototypes */
  328. int libLoadLibrary __ANSI_PROTO((char *));
  329. int libWriteLibrary __ANSI_PROTO((char *));
  330.  
  331.  
  332. /* Misc */
  333.  
  334. void checkContentType();
  335. void initStandardModule();
  336. void initMsqlModule();
  337. void initModules();
  338. void setError();
  339. int typeDetermineType __ANSI_PROTO((char*));
  340.  
  341.  
  342. /*
  343. ** Inline definitions
  344. */
  345.  
  346. /* inlined, unaligned, 4-byte copy */
  347. #define bcopy4(s,d) \
  348.       ((((unsigned char *)d)[0] = ((unsigned char *)s)[0]), \
  349.        (((unsigned char *)d)[1] = ((unsigned char *)s)[1]), \
  350.        (((unsigned char *)d)[2] = ((unsigned char *)s)[2]), \
  351.        (((unsigned char *)d)[3] = ((unsigned char *)s)[3]))
  352. /* inlined, unaligned, 8-byte copy */
  353. #define bcopy8(s,d) \
  354.       ((((unsigned char *)d)[0] = ((unsigned char *)s)[0]), \
  355.        (((unsigned char *)d)[1] = ((unsigned char *)s)[1]), \
  356.        (((unsigned char *)d)[2] = ((unsigned char *)s)[2]), \
  357.        (((unsigned char *)d)[3] = ((unsigned char *)s)[3]), \
  358.        (((unsigned char *)d)[4] = ((unsigned char *)s)[4]), \
  359.        (((unsigned char *)d)[5] = ((unsigned char *)s)[5]), \
  360.        (((unsigned char *)d)[6] = ((unsigned char *)s)[6]), \
  361.        (((unsigned char *)d)[7] = ((unsigned char *)s)[7]))
  362.  
  363.  
  364.  
  365. /*
  366. ** Macros for matching character classes.  These are in addition to
  367. ** those provided in <ctypes.h>
  368. */
  369.  
  370. #ifdef  iswhite
  371. # undef iswhite
  372. #endif
  373. #define iswhite(c)      (c == ' ' || c == '\t' || c == '\n')
  374.  
  375. #ifdef  iscompop
  376. # undef iscompop
  377. #endif
  378. #define iscompop(c)     (c == '<' || c == '>' || c == '=')
  379.  
  380.